package com.lc.service.impl;

import com.cnpc.framework.base.service.impl.BaseServiceImpl;

import com.lc.entity.BDResponse;
import com.lc.entity.TXResponse;
import com.lc.service.MapService;
import com.lc.utils.BaiduPostUtils;
import com.lc.utils.TXPostUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by 下雨不带伞 on 2019/7/18.
 */
@Service
public class MapServiceImpl extends BaseServiceImpl implements MapService {
    private final Logger LOG = LoggerFactory.getLogger(getClass().getSimpleName());


    @Override
    public TXResponse toTx(String type, String locations) throws Exception {
        Map<String, Object> params = new HashMap<>();

        params.put("type", type);
        params.put("locations", locations);


        return TXPostUtils.get("/coord/v1/translate/",params,TXResponse.class);
    }

    @Override
    public TXResponse calculateTXDistances(Double longitude, Double latitude, String vertexes, Integer mode) throws Exception {

        Map<String, Object> params = new HashMap<>();
        if (mode != null) {
            params.put("mode", mode==0?"driving":"walking");
        }

        params.put("from", latitude+","+longitude);
        params.put("to", vertexes);


        return TXPostUtils.get("/distance/v1/",params,TXResponse.class);
    }

    @Override
    public TXResponse locToAddress(Double longitude, Double latitude) throws Exception {
        Map<String, Object> params = new HashMap<>();


        params.put("location", latitude+","+longitude);
        params.put("get_poi", "1");


        return TXPostUtils.get("/geocoder/v1/",params,TXResponse.class);
    }

    @Override
    public BDResponse changePointTOBD(Double longitude, Double latitude) throws Exception {
        Map<String, Object> params = new HashMap<>();

        params.put("coords", longitude + "," + latitude);
        params.put("from", "3");
        params.put("to", "5");

        BDResponse response = BaiduPostUtils.getV1("http://api.map.baidu.com/geoconv/v1/", params, BDResponse.class);
        return response;
    }

    @Override
    public BDResponse changePointsTOBD(String vertexes) throws Exception {
        Map<String, Object> params = new HashMap<>();

        params.put("coords", vertexes);
        params.put("from", "3");
        params.put("to", "5");

        BDResponse response = BaiduPostUtils.getV1("http://api.map.baidu.com/geoconv/v1/", params, BDResponse.class);
        return response;
    }
}
